package demo00;

/**
 * 方式一：
 * extends Thread 方式创建线程类
 * 缺点是占用了继承类名额；不方便多个线程访问共享资源（必须使用 static 成员变量）
 */
public class ThreadDemo01 {

    public static void main(String[] args) throws InterruptedException {
        Cat cat01 = new Cat();
        cat01.start();

        Cat cat02 = new Cat();
        cat02.start();

        System.out.println("启动线程后，主线程不会阻塞！ " + Thread.currentThread().getName());

        for (int i = 0; i < 60; i++) {
            System.out.println("主线程：i=" + i);
            Thread.sleep(1000);
        }
    }
}

class Cat extends Thread {

    int times = 0;

    @Override
    public void run() {
        while (true) {
            System.out.println(Thread.currentThread().getName() + "：喵喵，我是小猫咪 " + (++times));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (times == 80) {
                break;
            }
        }
    }
}
